﻿using System.Collections.Generic;
using BlockLogic.Impl.Controller;
using CommandLogic.Interface;
using ActionLogic.Impl;
using System.Threading;
using System;

namespace CommandLogic.Impl
{
    public class RunCommand : ICommandLogic
    {
        private static readonly RunCommand Instance = new RunCommand();

        private RunCommand() { }

        public static RunCommand GetInstance()
        {
            return Instance;
        }

        public Dictionary<string, object> execute(Dictionary<string, object> param)
        {
            var blockController = BlockController.GetInstance();
            var executor = ActionExecutor.GetInstance();

            foreach (var block in blockController.Blocks)
            {
                block.Initialize();
            }

            GC.Collect();

            var thread = new Thread(executor.Run) {IsBackground = true};
            thread.Start();

            return null;
        }
    }
}
